const { get_file_list } = require("../utils/file_tool");
const { warn } = require("../utils/log_tool");
const { exec_shell } = require("../utils/shell_tool");
const { BaseCommand } = require("./base");

class RevealCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        const files = get_file_list(data.src);
        if (files.length === 0) {
            warn(`reveal 未匹配到文件 ${data.src}`);
        }
        for (let index = 0; index < files.length; index++) {
            const file = files[index];
            if (process.platform === "win32") {
                await exec_shell({
                    cmd: ["explorer", "/select,", file.replace(/\//g, "\\")],
                    // 这条命令的错误码为1
                    ignore_code: true,
                });
            } else {
                // TODO: 未测验
                await exec_shell({
                    cmd: ["start", file],
                });
            }
        }
    }
}

module.exports = {
    RevealCommand,
};
